package com.leyou.item.web;

import com.leyou.item.dto.CategoryDTO;
import com.leyou.item.service.CategoryService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/category")
public class CategoryController {

    private final CategoryService categoryService;

    public CategoryController(CategoryService categoryService) {
        this.categoryService = categoryService;
    }

    /**
     * 根据分类的父id查询对应的子的集合
     * @param pid
     * @return
     */
    @GetMapping("/of/parent")
    public ResponseEntity<List<CategoryDTO>> listCategoryByPid(
            @RequestParam("pid")Long pid){

        return ResponseEntity.ok(this.categoryService.listCategoryByPid(pid));
    }
    //根据分类ID查询商品分类
    @GetMapping("/{id}")
    public ResponseEntity<CategoryDTO> queryCategoryById(@PathVariable("id") long id){

        return ResponseEntity.ok(this.categoryService.queryCategoryById(id));
    }
//根据分类id的集合，查询商品分类的集合
    @GetMapping("/list")
    public ResponseEntity<List<CategoryDTO>> listCategoryByIds(@RequestParam("ids") List<Long> ids){
        return ResponseEntity.ok(this.categoryService.listCategoryByIds(ids));
    }
    //根据品牌id，查询商品分类的集合
    /**
     * 根据品牌id查询分类集合
     * @param brandId 品牌id
     * @return 分类集合
     */
    @GetMapping("/of/brand")
    public ResponseEntity<List<CategoryDTO>> queryCategoryByBrandId(@RequestParam("id") Long brandId){
        return ResponseEntity.ok(categoryService.queryCategoryByBrandId(brandId));
    }

}
